package co.yixiang.yshop.server.chaos;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.boot.web.servlet.FilterRegistrationBean;

@Configuration
@EnableConfigurationProperties(ChaosProperties.class)
public class ChaosConfiguration {

    @Bean
    public FilterRegistrationBean<ChaosFilter> chaosFilterRegistration(ChaosProperties properties) {
        FilterRegistrationBean<ChaosFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new ChaosFilter(properties));
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE + 50);
        registration.addUrlPatterns("/*");
        registration.setName("chaosFilter");
        registration.setEnabled(true);
        return registration;
    }
} 